package com.example.mylibrarybase.yumengmeng15.adapter;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.mylibrarybase.R;
import com.example.mylibrarybase.utils.LogUtils;
import com.example.mylibrarybase.yumengmeng04.base.BaseListViewAdapter_04;
import com.example.mylibrarybase.yumengmeng04.view.MyViewHolder_04;
import com.example.mylibrarybase.yumengmeng15.bean.items;
import com.example.mylibrarybase.yumengmeng15.utils.Utilsflexible;

import java.util.ArrayList;

/**
 * Created by 35876 于萌萌
 * 创建日期: 17:21 . 2016年10月24日
 * 描述:
 * <p>
 * <p>
 * 备注:
 */

public class MyListView_15 extends BaseListViewAdapter_04<items> {
        ArrayList<String> mTextViews = new ArrayList<>();
    private int mHeight;

    public MyListView_15(Context context, int type, ArrayList datas, CallBack mCallBack) {
        super(context, type, datas, mCallBack);
    }
    public int getViewType(items itemss ,int position){
        if (position == mDatas.size()) {
            return R.layout.load_more;
        } else {
            return R.layout.flexiblerelativelayout_15;
        }
    }
    @Override
    public void convert(MyViewHolder_04 helper, final items s, int position) {

        TextView textView = helper.initText(R.id.tv_1, s.s);
        final TextView flexiblelinearlayout_15_tv = helper.initText(R.id.flexiblelinearlayout_15_tv, s.s);
        final LinearLayout linearLayout = helper.initLinearLayout(mContext, R.id.flexiblelinearlayout_15_ll);
        //listview item 要重新测量 才会有数值
        linearLayout.measure(0, 0);
        int mHeights= linearLayout.getLayoutParams().height;
        mHeight= linearLayout.getMeasuredHeight();
        LogUtils.i("当前高度是"+mHeight+mHeights);
        if (!mTextViews.contains(s.id)){
            LogUtils.i("我点开了id没有"+mHeight);
            flexiblelinearlayout_15_tv.setTag(false);
            linearLayout.getLayoutParams().height=0;

        }else{
            LogUtils.i("我点开了id有"+mHeight);
            flexiblelinearlayout_15_tv.setTag(true);
            linearLayout.getLayoutParams().height=mHeight;
        }

        flexiblelinearlayout_15_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!(boolean) flexiblelinearlayout_15_tv.getTag()){
                    mTextViews.add(s.id);
                    LogUtils.i("我点开了我要添加id过去"+s.id+"集合数据"+mTextViews);
                }else{
                    mTextViews.remove(s.id);
                    LogUtils.i("我点开了我要删除id过去"+s.id+"集合数据"+mTextViews);
                }
                Utilsflexible.sumbit(flexiblelinearlayout_15_tv, linearLayout);
            }
        });
    }
}
